/*
 * ShoppingCartShopListItem.java
 * business
 *
 * Created by SunDing on 2016/9/9.
 *
 * Copyright (c) 2016年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.listview.displaylistitem;

import android.app.Activity;
import android.content.Context;
import android.view.View;

import com.yidiandao.business.data.bean.Shop;
import com.yidiandao.business.data.model.IShoppingCartModel;
import com.yidiandao.business.data.model.ShoppingCartModel;
import com.yidiandao.business.manager.ShoppingCartManager;
import com.yidiandao.business.ui.shopdetail.ShopDetailActivity;
import com.yidiandao.business.ui.widget.listview.DisplayListItem;

/** 购物车-商品所属店铺 Item */
public class ShoppingCartShopListItem extends DisplayListItem<ShoppingCartShopHolder, Shop> {

    private IShoppingCartModel mShoppingCartModel;

    public ShoppingCartShopListItem(Shop s) {
        super(s);
        mShoppingCartModel = new ShoppingCartModel();
    }

    @Override
    public void onShow(final Context context, final ShoppingCartShopHolder holder) {
        holder.refreshUI(data);

        holder.mRlytSelect.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        boolean checked = holder.mCbSelect.isChecked();
                        ShoppingCartManager.getInstance().selectAllGoodsOfShop(data, !checked);
                        ShoppingCartManager.getInstance().clearOrSelectAllGoodsByShop(data);
                        mShoppingCartModel.postRefreshShoppingCartState(false);
                    }
                });

        holder.root.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (!data.isEditMode()) {
                            ShopDetailActivity.actionStart(
                                    (Activity) context, data.getSupplierId());
                        }
                    }
                });
    }

    @Override
    public String getDisplayItemTag() {
        return ShoppingCartShopListItem.class.getSimpleName();
    }

    @Override
    public Class<ShoppingCartShopHolder> getViewHolderClazz() {
        return ShoppingCartShopHolder.class;
    }
}
